<template>
    <!--历年选题-->
    <div class="class-contain">
        <ul>
            <li class="course-page" v-for="page in pageList" :key="page.id">
                <div class="page">
                    <div class="page-name">{{ page.test_name }}</div>
                    <div class="btn-box">
                    <!--    <a class="btn" @click="handleJumpHistory(page)">查看记录</a>-->
                        <a class="btn info" @click="handleJumpStartAnswer(page)">开始答题</a>
                    </div>
                </div>
            </li>
            <li class="no-data" v-if="pageList&&pageList.length ===0">暂无历史真题</li>
        </ul>
    </div>
</template>
<script>
export default {
    name: 'historyTestList',
    components: {
        /**/
    },
    data() {
        return {
            activePage: null,
            pageList: null
        };
    },
    props: {
        courseId: {},
        cataId: {},
        chaIndex: {}
    },
    watch: {
        // eslint-disable-next-line no-unused-vars
        courseId(val) {
            this.getList();
        }
    },
    mounted() {
        this.getList();
    },
    methods: {
        // 历年试卷列表
        getList() {
            return this.$api.ajaxData({
                pathName: 'doHisTrueTestList',
                authorization: true,
                errorFunc: false,
                data: {
                    course_id: this.courseId
                },
                method: 'post'
            }).then(res => {
                this.pageList = res.obj;
            }).catch(() => {
                this.pageList = [];
            });
        },
        // 查看答题历史
        handleJumpHistory(obj) {
            console.log(obj);
            let routeData = this.$router.resolve({
                name: 'analysis', query: {
                    test_id: obj.test_id,
                    batch_id: obj.batch_id
                }
            });
            window.open(routeData.href, '_blank');
        },
        // 开始答题
        handleJumpStartAnswer(obj) {
            let routeData = this.$router.resolve({
                name: 'test', query: {
                    type: 2,
                    test_id: obj.id,
                    test_type: 3,
                    test_name:obj.test_name,
                    sec_lab_name:obj.secend_lab_name,
                    course_id:obj.course_id,
                    batch_id: this.$util.dateConverter('yyyyMMddhhmmss')
                }
            });
            window.open(routeData.href, '_blank');
        }
    }
};
</script>
<style scoped lang="scss">
.energy-box {
    display: block;
    width: 80%;
    height: 6px;
    border-radius: 3px;
    background: rgba(204, 204, 204, 1);

    .energy-bar {
        height: 6px;
        min-width: 1%;
        border-radius: 3px;
        background: #006ade;
    }
}

ul, li, p {
    margin: 0;
}

.course-page {
    border-bottom: 1px solid #f7f7f7;

    .page {
        display: flex;
        height: 50px;
        padding: 0 20px;
        align-items: center;

        .fold-arrow {
            @include triangle(12px, #ccc, right);
            cursor: pointer;
            transition-duration: 200ms;

            &.active {
                transform: rotate(90deg);
            }
        }

        .page-name {
            flex: 1;
            margin: 0 10px;
            cursor: pointer;
        }

        .progress-box {
            display: flex;
            width: 300px;
            flex-shrink: 4;
            align-items: center;

            span {
                margin: 0 0 0 10px;
                color: #a1a1a1;
            }
        }

        .btn-box {
            .btn {
                padding: 0 5px;

                &:not(:first-child) {
                    border-left: 1px solid #eee;
                }

                &.info {
                    display: inline-block;
                    line-height: 24px;
                    padding: 0 15px;
                    margin-left: 15px;
                    border-radius: 12px;
                    border-left: none;
                    background: #007aff;
                    color: #fff;
                }

                &:hover {
                    opacity: 0.8;
                }
            }

        }
    }

    .page-item-list {
        li {
            display: flex;
            align-items: center;
            height: 50px;
            padding: 0 40px;
            border-top: 1px solid #f7f7f7;

            .item-name {
                flex: 1;
                cursor: pointer;
            }

            .progress-box {
                display: flex;
                align-items: center;
                width: 300px;

                span {
                    margin: 0 0 0 10px;
                    color: #a1a1a1;
                }
            }

            .icon-video {
                display: block;
                width: 15px;
                height: 15px;
                margin: 0 35px;
                background: url("../../../assets/image/icon/u2129.png") no-repeat;
                background-size: cover;
            }
        }
    }
}

.video {
    .course-page {
        border-bottom: none;
    }

    .page-item-list {
        li {
            border-top: none;

            .item-name {
                cursor: pointer;
                color: #999;
            }
        }
    }

    .page-name {
        font-size: 16px;
        color: #fff;
    }
}

.no-data {
    padding: 40px;
    text-align: center;
    color: #999;
}
</style>
